/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef IMAGE_KNIFE_C_KEKE_IMAGE_DATA_H
#define IMAGE_KNIFE_C_KEKE_IMAGE_DATA_H

#include <multimedia/image_framework/image/pixelmap_native.h>

namespace ImageKnifeC {
struct ImageData {
public:
    explicit ImageData(OH_PixelmapNative *pixelmap) : pixelmapList_(new OH_PixelmapNative *[1]), frameCount_(1)
    {
        pixelmapList_[0] = pixelmap;
    }

    ImageData(OH_PixelmapNative **pixelmapList, int *delayTimeList, size_t frameCount) : pixelmapList_(pixelmapList),
        delayTimeList_(delayTimeList), frameCount_(frameCount)
    {
    }

    OH_PixelmapNative *GetPixelmap() const
    {
        return pixelmapList_[0];
    }

    OH_PixelmapNative **GetPixelmapList() const
    {
        return pixelmapList_;
    }

    int *GetDelayTimeList() const
    {
        return delayTimeList_;
    }

    uint32_t GetFrameCount() const
    {
        return frameCount_;
    }

    ~ImageData()
    {
        if (pixelmapList_ != nullptr) {
            for (int i = 0; i < frameCount_; i++)
            {
                OH_PixelmapNative_Release(pixelmapList_[i]);
            }

            delete [] pixelmapList_;    
        }

        if (delayTimeList_ != nullptr) {
            delete [] delayTimeList_;
        }
    }

    ImageData(const ImageData&) = delete;
    ImageData& operator = (const ImageData&) = delete;
private:
    // 禁止修改图片数据地址，防止错误析构和内存泄漏
    OH_PixelmapNative **pixelmapList_ = nullptr;
    int *delayTimeList_ = nullptr;
    uint32_t frameCount_ = 0;
};

}

#endif //IMAGE_KNIFE_C_KEKE_IMAGE_DATA_H
